package primalgorithms.string;

public class _02ReverseInt {
    public static int reverse(int x) {
        if(x > -10 && x < 10){
            return x;
        }
        int res = 0;
        int remain = x,i = 0;
        while (remain != 0){
            int num = remain % 10;
            int newNum = res*10 + num;
            //如果溢出，那么新的数和原数的关系一定不是10倍关系
            if((newNum-num)/10 != res){
                return 0;
            }
            res = newNum;
            remain /= 10;
        }
        return res;
    }
}
